#include<bits/stdc++.h>
using namespace std;
const int N=1e6+10;
#define ll long long
ll col[N];
ll T,n;
ll a[N];
ll ans=0;

int main(){
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    scanf("%lld",&T);
    while(T--){
        ans=0;
        scanf("%lld",&n);
        for(int i=1;i<=n;i++){
            scanf("%lld",&a[i]);
        }
        ll cnt=0;
        for(int i=1;i<=n;i++){
            memset(col,0,sizeof(col));
            for(int j=1;j<=i;j++){
                col[j]=1;
            }
            sort(col+1,col+1+n);
            do{
                /*cnt++;
                cout<<"l";
                for(int i=1;i<=n;i++){
                    cout<<col[i]<<" ";
                }
                cout<<endl;*/
                ll anss=0;
                for(int j=1;j<=n;j++){
                    for(int l=j-1;l>=1;l--){
                        if(col[l]==col[j]){
                            if(a[l]==a[j]) anss+=a[l];
                            break;
                        }
                    }
                }
                //cout<<anss<<endl;
                ans=max(ans,anss);
            }while(next_permutation(col+1,col+n+1));
        }
        printf("%lld\n",ans);
        //cout<<cnt<<endl;
    }
    return 0;
}